package com.ttc.mBackup.BackupImages;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.ttc.mBackup.R;
public class CustomGridviewAdapter extends BaseAdapter {

	private Context mContext;
	ArrayList<CustomGridviewItem> lstItems;
	
	public CustomGridviewAdapter(Context c, ArrayList<CustomGridviewItem> lstItems) {
		// TODO Auto-generated constructor stub
		mContext = c;
		this.lstItems = lstItems;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lstItems.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return lstItems.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View grid;

		if (convertView == null) {
			grid = new View(mContext);
			LayoutInflater inflater =(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			grid = inflater.inflate(R.layout.i_custom_gridview, parent, false);
		} else {
			grid = (View) convertView;
		}

		ImageView imageView = (ImageView) grid.findViewById(R.id.i_custom_gridview_imageview);
		//TextView textView = (TextView) grid.findViewById(R.id.textpart);
		
		Bitmap bm = ImageManager.getImage(lstItems.get(position).getImagePath());
		Log.v("mediastore","abc: " +  lstItems.get(position).getImagePath());
		if(bm!=null) imageView.setImageBitmap(bm);
		Log.v("mediastore","abc: " +  lstItems.get(position).getImagePath());
		Log.v("mediastore","abc size: " +  bm.getHeight() + " : " + bm.getWidth());
		

		//textView.setText(String.valueOf(position));

		return grid;
	}

}
